#pragma once
#include <map>
#include <string>
#include <Windows.h>

#define CP_GBK 936

using namespace std;

/*
*\class suHttpParser: a simple HTTP parser
*use example:
*suHttpParser parser;
*parser.is
*/
class suHttpParser
{
public:
	suHttpParser(void);
	~suHttpParser(void);
public:
	typedef map<string, string>			MIMETYPES;
	MIMETYPES  m_MimeTypes;
	enum       {UNKNOWN,GET,POST};
	string     m_HomeDir;
	string     m_DefalutHomepage;
	string     m_requestFilename;
	string	   m_getParameter;
	string     m_soapAction;
	string     m_soapReturn;
	string     m_postParameter;
	string     m_strResponse;
	int        m_httpMethod;


public:
	//http method
	BOOL ParseRequest (string szRequest, string &szResponse, BOOL &bKeepAlive);
	BOOL isValidGet   (string szRequest);   // check HTTP GET head; Set m_requestFilename=request string follows GET
	BOOL isValidPost  (string szRequest);   // c// check HTTP POST head Set m_requestFilename=request string follows POST
	BOOL getParameter ();                   // check GET parameters, if return TRUE: m_requestFilename = ServiceName; m_requestParameter=parameter follows m_requestFilename
	BOOL getSoapAction(string szRequest);
	
	BOOL genHttpGetResponse  (string szRequest);
	BOOL genWsdlResponse     (string szWsdl);//gen wdsl xml response
	BOOL genNotFoundResonse  ();
	BOOL genPostResonse      (string strReturn); //gen web service response

private:
	string GBK2UTF(string gbkStr);
	string UTF2GBK(string utf8Str);
private:
	string serverName_;
	string contentType_;
	BOOL   bKeepAlive_;

};


